<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>explain之extra | Manor Farm Mysql</title>
    <meta name="generator" content="VuePress 1.7.1">
    <link rel="icon" href="/manor-farm-mysql/pgmanor_mysql.svg">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css">
    <script language="javascript" type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="/manor-farm-mysql/js/MouseClickEffect.js"></script>
    <script language="javascript" type="text/javascript" src="/manor-farm-mysql/js/pgmanor-self.js"></script>
    <meta name="description" content="Mysql学习手册">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/manor-farm-mysql/assets/css/0.styles.7bfce8db.css" as="style"><link rel="preload" href="/manor-farm-mysql/assets/js/app.bbd54b43.js" as="script"><link rel="preload" href="/manor-farm-mysql/assets/js/3.33fa8ee0.js" as="script"><link rel="preload" href="/manor-farm-mysql/assets/js/1.e501e4e7.js" as="script"><link rel="preload" href="/manor-farm-mysql/assets/js/24.560a4164.js" as="script"><link rel="preload" href="/manor-farm-mysql/assets/js/8.73e907b5.js" as="script"><link rel="prefetch" href="/manor-farm-mysql/assets/js/10.31e485b8.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/11.bd87e4cf.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/12.0fe1282f.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/13.f1de335a.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/14.4a84a4ee.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/15.bc190a07.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/16.3f42a3ab.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/17.f1cad67c.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/18.e8063fee.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/19.068739ed.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/20.2b248747.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/21.4fd4cbc1.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/22.2683cc54.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/23.2e39bbe5.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/25.26555323.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/26.8b7e1943.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/27.0f4ac9a1.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/28.f89ec4c0.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/29.71c751c3.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/30.ad576991.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/31.2746a45e.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/32.b62e21d8.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/33.ae9d6c1c.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/34.53969cd0.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/35.3e1a8a01.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/36.eb74300d.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/37.16568451.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/38.9a3bc894.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/39.7aab5a75.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/4.c231685d.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/40.cd44603a.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/41.64d0c11a.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/42.3fb5d657.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/43.d4f19236.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/44.6abd5f31.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/45.eaf7b761.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/46.d891856e.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/5.0292b513.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/6.df2ba939.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/7.3b1acb14.js"><link rel="prefetch" href="/manor-farm-mysql/assets/js/9.5220a7da.js">
    <link rel="stylesheet" href="/manor-farm-mysql/assets/css/0.styles.7bfce8db.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-2d5f533b><div data-v-2d5f533b><div id="loader-wrapper" class="loading-wrapper" data-v-d48f4d20 data-v-2d5f533b data-v-2d5f533b><div class="loader-main" data-v-d48f4d20><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-59a94c5a data-v-2d5f533b data-v-2d5f533b><h3 class="title" style="display:none;" data-v-59a94c5a data-v-59a94c5a>Manor Farm Mysql</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-59a94c5a data-v-59a94c5a><input type="password" value="" data-v-59a94c5a> <span data-v-59a94c5a>已加密!</span> <button data-v-59a94c5a>OK</button></label> <div class="footer" style="display:none;" data-v-59a94c5a data-v-59a94c5a><span data-v-59a94c5a><i class="iconfont reco-eye" data-v-59a94c5a></i> <a target="blank" href="https://pgmanor.gitee.io/blog/" data-v-59a94c5a>密钥</a></span> <span data-v-59a94c5a><i class="iconfont reco-theme" data-v-59a94c5a></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59a94c5a>vuePress-theme-reco</a></span> <span data-v-59a94c5a><i class="iconfont reco-copyright" data-v-59a94c5a></i> <a data-v-59a94c5a><span data-v-59a94c5a>pgmanor</span>
  
<!---->
2021
</a></span></div></div> <div class="hide" data-v-2d5f533b><header class="navbar" data-v-2d5f533b><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/manor-farm-mysql/" class="home-link router-link-active"><img src="/manor-farm-mysql/pgmanor_mysql.svg" alt="Manor Farm Mysql" class="logo"> <span class="site-name">Manor Farm Mysql</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/manor-farm-mysql/zh/guide/" class="nav-link router-link-active"><i class="iconfont reco-api"></i>
  指南
</a></div><div class="nav-item"><a href="/manor-farm-mysql/zh/fix/messageBoard.html" class="nav-link"><i class="iconfont reco-suggestion"></i>
  留言版
</a></div><div class="nav-item"><a href="https://pgmanor.gitee.io/blog/2021/01/10/secret-farm-mysql/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-eye"></i>
  文章密钥
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-qq"></i>
      联系
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>QQ在线</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://wpa.qq.com/msgrd?v=3&amp;uin=2307546059&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  pgmanor
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li><li class="dropdown-item"><h4>其他方式</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/manor-farm-mysql/zh/fix/contactUs.html" class="nav-link"><i class="iconfont undefined"></i>
  更多
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-other"></i>
      友链
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>博客</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://pgmanor.gitee.io/blog/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  pgmanor
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://blog.csdn.net/u011622109" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-csd"></i>
  csdn
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://www.iworkh.com" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  iworkh
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li><li class="dropdown-item"><h4>Vue</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://cn.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  Vue
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://v1.vuepress.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  VuePress
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://vuepress-theme-reco.recoluan.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  vuepress-theme-reco
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul></div></div><div class="nav-item"><a href="/manor-farm-mysql/zh/fix/donate.html" class="nav-link"><i class="iconfont reco-Coding"></i>
  捐赠
</a></div><div class="nav-item"><a href="https://gitee.com/pgmanor/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-2d5f533b></div> <aside class="sidebar" data-v-2d5f533b><div class="personal-info-wrapper" data-v-ca798c94 data-v-2d5f533b><img src="/manor-farm-mysql/pgmanor_mysql.svg" alt="author-avatar" class="personal-img" data-v-ca798c94> <h3 class="name" data-v-ca798c94>
    pgmanor
  </h3> <div class="num" data-v-ca798c94><div data-v-ca798c94><h3 data-v-ca798c94>30</h3> <h6 data-v-ca798c94>文章</h6></div> <div data-v-ca798c94><h3 data-v-ca798c94>26</h3> <h6 data-v-ca798c94>标签</h6></div></div> <hr data-v-ca798c94></div> <nav class="nav-links"><div class="nav-item"><a href="/manor-farm-mysql/zh/guide/" class="nav-link router-link-active"><i class="iconfont reco-api"></i>
  指南
</a></div><div class="nav-item"><a href="/manor-farm-mysql/zh/fix/messageBoard.html" class="nav-link"><i class="iconfont reco-suggestion"></i>
  留言版
</a></div><div class="nav-item"><a href="https://pgmanor.gitee.io/blog/2021/01/10/secret-farm-mysql/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-eye"></i>
  文章密钥
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-qq"></i>
      联系
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>QQ在线</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://wpa.qq.com/msgrd?v=3&amp;uin=2307546059&amp;site=qq&amp;menu=yes" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  pgmanor
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li><li class="dropdown-item"><h4>其他方式</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/manor-farm-mysql/zh/fix/contactUs.html" class="nav-link"><i class="iconfont undefined"></i>
  更多
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-other"></i>
      友链
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>博客</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://pgmanor.gitee.io/blog/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  pgmanor
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://blog.csdn.net/u011622109" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-csd"></i>
  csdn
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://www.iworkh.com" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  iworkh
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li><li class="dropdown-item"><h4>Vue</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://cn.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  Vue
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://v1.vuepress.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  VuePress
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-subitem"><a href="https://vuepress-theme-reco.recoluan.com/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont undefined"></i>
  vuepress-theme-reco
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul></div></div><div class="nav-item"><a href="/manor-farm-mysql/zh/fix/donate.html" class="nav-link"><i class="iconfont reco-Coding"></i>
  捐赠
</a></div><div class="nav-item"><a href="https://gitee.com/pgmanor/" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav> <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>初入尘世</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/manor-farm-mysql/zh/guide/essentials/e-01-install.html" class="sidebar-link">安装</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-02-ddl-dcl.html" class="sidebar-link">DDL语句</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-03-dml.html" class="sidebar-link">DML语句</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-04-sort.html" class="sidebar-link">sort排序</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-05-group.html" class="sidebar-link">group分组</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-06-union.html" class="sidebar-link">union合并</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-07-join.html" class="sidebar-link">join</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-08-transaction.html" class="sidebar-link">事务</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-09-view.html" class="sidebar-link">视图</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-10-procedure.html" class="sidebar-link">存储过程</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-11-function.html" class="sidebar-link">函数</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-12-index.html" class="sidebar-link">索引</a></li><li><a href="/manor-farm-mysql/zh/guide/essentials/e-13-devops.html" class="sidebar-link">运维</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>千锤百炼</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/manor-farm-mysql/zh/guide/advanced/a-01-introduction.html" class="sidebar-link">本章介绍</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/a-02-prepare-data.html" class="sidebar-link">数据准备</a></li><li><section class="sidebar-group collapsable is-sub-group depth-1"><a href="/manor-farm-mysql/zh/guide/" class="sidebar-heading clickable router-link-active"><span>原理</span> <span class="arrow right"></span></a> <!----></section></li><li><section class="sidebar-group collapsable is-sub-group depth-1"><a href="/manor-farm-mysql/zh/guide/" class="sidebar-heading clickable router-link-active open"><span>优化</span> <span class="arrow down"></span></a> <ul class="sidebar-links sidebar-group-items"><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-01-slow-query.html" class="sidebar-link">慢查询</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-02-mysqldumpslow.html" class="sidebar-link">mysqldumpslow</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-03-explain.html" class="sidebar-link">explain</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-04-explain-select-type.html" class="sidebar-link">explain之select_type</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-05-explain-type.html" class="sidebar-link">explain之type</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-06-explain-extra.html" aria-current="page" class="active sidebar-link">explain之extra</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-07-optimization.html" class="sidebar-link">优化思路和手段</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-08-optimization-join.html" class="sidebar-link">优化之join</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-09-optimization-orderby.html" class="sidebar-link">优化之排序</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-10-optimization-groupby.html" class="sidebar-link">优化之分组</a></li><li><a href="/manor-farm-mysql/zh/guide/advanced/optimization/a-11-optimization-struct.html" class="sidebar-link">结构优化</a></li></ul></section></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>百战成神</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-59a94c5a data-v-2d5f533b><h3 class="title" style="display:none;" data-v-59a94c5a data-v-59a94c5a>explain之extra</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-59a94c5a data-v-59a94c5a><input type="password" value="" data-v-59a94c5a> <span data-v-59a94c5a>已加密!</span> <button data-v-59a94c5a>OK</button></label> <div class="footer" style="display:none;" data-v-59a94c5a data-v-59a94c5a><span data-v-59a94c5a><i class="iconfont reco-eye" data-v-59a94c5a></i> <a target="blank" href="https://pgmanor.gitee.io/blog/" data-v-59a94c5a>密钥</a></span> <span data-v-59a94c5a><i class="iconfont reco-theme" data-v-59a94c5a></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59a94c5a>vuePress-theme-reco</a></span> <span data-v-59a94c5a><i class="iconfont reco-copyright" data-v-59a94c5a></i> <a data-v-59a94c5a><span data-v-59a94c5a>pgmanor</span>
  
<!---->
2021
</a></span></div></div> <div data-v-2d5f533b><main class="page"><div class="page-title" style="display:none;"><h1 class="title">explain之extra</h1> <div data-v-3b7f5bdf><i class="iconfont reco-account" data-v-3b7f5bdf><span data-v-3b7f5bdf>pgmanor</span></i> <i class="iconfont reco-date" data-v-3b7f5bdf><span data-v-3b7f5bdf>2021-01-02</span></i> <i class="iconfont reco-eye" data-v-3b7f5bdf><span id="/manor-farm-mysql/zh/guide/advanced/optimization/a-06-explain-extra.html" data-flag-title="Your Article Title" class="leancloud-visitors" data-v-3b7f5bdf><a class="leancloud-visitors-count" style="font-size:.9rem;font-weight:normal;color:#999;"></a></span></i> <i class="iconfont reco-tag tags" data-v-3b7f5bdf><span class="tag-item" data-v-3b7f5bdf>explain</span></i></div></div> <div class="theme-reco-content content__default" style="display:none;"><p>本文主要介绍下explain的extra <a href="https://dev.mysql.com/doc/refman/8.0/en/explain-output.html#explain_ref" target="_blank" rel="noopener noreferrer">EXPLAIN Extra Information<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <div id="boxx" data-v-f4ca0dac><div data-v-f4ca0dac><p v-if="true" class="custom-block-title" data-v-f4ca0dac></p> <p v-if="true" data-v-f4ca0dac></p></div></div> <h2 id="_1-extra值">1.extra值</h2> <ul><li>distinct：在select部分使用了distinc关键字，优化Distinct操作，在找到匹配的第一行记录后，立马停止查找同样的值</li> <li>no tables used：不带from字句的查询或者From dual查询</li> <li>NULL: 查询的列，没有被索引覆盖到。where条件是索引列，查询使用了索引(key有值)，但是查询的字段不在索引中，需要通过<strong>回表</strong>查询才能实现。</li> <li>using index：查询时不需要回表查询，直接通过索引就可以获取查询的数据。</li> <li>using where：查询的列未被索引覆盖到，where条件不是索引前导列</li> <li>using where using index: 查询字段和where条件字段在索引中，但是where条件不满足前导列索引</li> <li>using index condtion: 查询字段不在索引中，where条件满足前置索引的范围性查询</li> <li>using temporary: 使用临时表存储中间结果。临时表可以是内存、磁盘临时表</li> <li>using filesort：排序时无法使用到索引时，就会出现这个。常见于order by语句中</li> <li>使用not in()形式子查询或not exists运算符的连接查询，这种叫做反连接。即，一般连接查询是先查询内表，再查询外表，反连接就是先查询外表，再查询内表。</li> <li>using join buffer（block nested loop），using join buffer（batched key accss）：5.6.x之后的版本优化关联查询的BNL，BKA特性。主要是减少内表的循环数量以及比较顺序地扫描查询。</li> <li>using sort_union，using_union，using intersect，using sort_intersection
<ul><li>using intersect：表示使用and的各个索引的条件时，该信息表示是从处理结果获取交集</li> <li>using union：表示使用or连接各个使用索引的条件时，该信息表示从处理结果获取并集</li></ul></li> <li>using sort_union和using sort_intersection：与前面两个对应的类似，只是他们是出现在用and和or查询信息量大时，先查询主键，然后进行排序合并后，才能读取记录并返回。</li> <li>firstmatch(tb_name)：5.6.x开始引入的优化子查询的新特性之一，常见于where字句含有in()类型的子查询。如果内表的数据量比较大，就可能出现这个</li> <li>loosescan(m..n)：5.6.x之后引入的优化子查询的新特性之一，在in()类型的子查询中，子查询返回的可能有重复记录时，就可能出现这个</li></ul> <h2 id="_2-no-tables-used">2.no tables used</h2> <p>no tables used：不带from字句的查询或者From dual查询</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token comment">-- 函数</span>
<span class="token keyword">explain</span> <span class="token keyword">select</span> <span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span> 

<span class="token comment">-- dual表</span>
<span class="token keyword">explain</span> <span class="token keyword">select</span> <span class="token number">1</span> <span class="token keyword">from</span> dual<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td>No tables used</td></tr></tbody></table> <blockquote><p>一些常用的函数或从<code>dual</code>查询，<code>Extra</code>都会显示<code>No tables used</code></p></blockquote> <h2 id="_3-null">3.NULL</h2> <p>查询的列，没有被索引覆盖到。where条件是索引列，查询使用了索引(key有值)，但是查询的字段不在索引中，需要通过<strong>回表</strong>查询才能实现。</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> film 
<span class="token keyword">where</span> title <span class="token operator">=</span> <span class="token string">'AFRICAN EGG'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>ref</td> <td>idx_title</td> <td>idx_title</td> <td>514</td> <td>const</td> <td>1</td> <td>100.0</td> <td></td></tr></tbody></table> <blockquote><p><code>key</code>有值为<code>idx_title</code>,所以走了索引，但是查询的是所有列，需要通过回表查询才可以。</p></blockquote> <h2 id="_4-using-index">4.Using index</h2> <p>查询时不需要回表查询，直接通过索引就可以获取查询的数据。</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> title <span class="token keyword">from</span> film 
<span class="token keyword">where</span> title <span class="token operator">=</span> <span class="token string">'AFRICAN EGG'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>ref</td> <td>idx_title</td> <td>idx_title</td> <td>514</td> <td>const</td> <td>1</td> <td>100.0</td> <td>Using index</td></tr></tbody></table> <blockquote><p>查询的字段就在索引中，所以不需要回表查询了。</p></blockquote> <h2 id="_5-using-where">5.using where</h2> <p>表示存储引擎返回的记录并不是所有的都满足查询条件，需要在server层进行过滤。查询条件中分为限制条件和检查条件。</p> <ul><li>5.6之前，存储引擎只能根据限制条件扫描数据并返回，然后server层根据检查条件进行过滤再返回真正符合查询的数据。</li> <li>5.6.x之后支持ICP特性，可以把检查条件也下推到存储引擎层，不符合检查条件和限制条件的数据，直接不读取，这样就大大减少了存储引擎扫描的记录数量。</li></ul> <blockquote><p>大白话，where条件没有索引</p></blockquote> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> rating <span class="token keyword">from</span> film 
<span class="token keyword">where</span> rating <span class="token operator">=</span> <span class="token string">'PG'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>ALL</td> <td></td> <td></td> <td></td> <td></td> <td>1000</td> <td>20.0</td> <td>Using where</td></tr></tbody></table> <blockquote><p>rating为非索引字段</p></blockquote> <h2 id="_6-using-where-using-index">6.using where using index</h2> <p>查询的列在索引中，where条件走了索引，但是索引不是走的前导列。</p> <blockquote><p>无法通过索引查找满足条件的数据</p></blockquote> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>student<span class="token punctuation">`</span> <span class="token punctuation">(</span>
  <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">'id'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span> <span class="token keyword">COLLATE</span> utf8mb4_general_ci <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'姓名'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>age<span class="token punctuation">`</span> <span class="token keyword">int</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'年龄'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>sex<span class="token punctuation">`</span> <span class="token keyword">bit</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'性别'</span><span class="token punctuation">,</span>
  <span class="token punctuation">`</span>email<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span> <span class="token keyword">COLLATE</span> utf8mb4_general_ci <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">'邮件'</span><span class="token punctuation">,</span>
  <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token keyword">KEY</span> <span class="token punctuation">`</span>index_name_age<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>name<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>age<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">InnoDB</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token operator">=</span><span class="token number">100069</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span><span class="token operator">=</span>utf8mb4 <span class="token keyword">COLLATE</span><span class="token operator">=</span>utf8mb4_general_ci<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><strong>查询sql</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span>  name<span class="token punctuation">,</span> age<span class="token punctuation">,</span> id <span class="token keyword">from</span> student 
<span class="token keyword">where</span> name <span class="token operator">=</span> <span class="token string">'pgmanor'</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>student</td> <td></td> <td>index</td> <td>index_age_name</td> <td>index_age_name</td> <td>408</td> <td></td> <td>99839</td> <td>10.0</td> <td>Using where; Using index</td></tr></tbody></table> <blockquote><p>条件<code>name</code>和字段<code>name, age, id</code>都在<code>index_age_name</code>索引中，但<code>name</code>是不是前导列，所以是<code>Using where</code>，
而取值刚好在索引中，所以是<code>Using index</code></p></blockquote> <h2 id="_7-using-index-condition">7.Using index condition</h2> <p>Using index condition 使用了Index Condition Pushdown (IPC)</p> <blockquote><p>这是Mysql 5.6开始支持的一种根据索引进行查询的优化方式。其优化支持range、ref、eq_ref、ref_or_null类型的查询，支持MyISAM和InnoDB存储引擎。</p></blockquote> <p>满足以下条件才会出现Using index condition</p> <ul><li>where条件满足前置索引</li> <li>查询列有不在索引中，即索引没有覆盖到要查询的字段</li> <li>而且是个小范围查询，如果是一条或者太多条，也不行</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> age<span class="token punctuation">,</span>name<span class="token punctuation">,</span>email <span class="token keyword">from</span> student 
<span class="token keyword">where</span> age <span class="token operator">&lt;</span> <span class="token number">20</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>student</td> <td></td> <td>range</td> <td>index_age_name</td> <td>index_age_name</td> <td>5</td> <td></td> <td>16</td> <td>100.0</td> <td>Using index condition</td></tr></tbody></table> <blockquote><p>将sql<code>where age &lt; 20</code> 修改为<code>=</code>或者<code>&gt;</code>试下，出来的结果也会不一样</p></blockquote> <h2 id="_8-using-temporary">8.Using temporary</h2> <p><strong>using temporary</strong>: 使用临时表存储中间结果。临时表可以是内存、磁盘临时表，常见于排序分组group by和distinct中</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> 
<span class="token keyword">select</span> <span class="token keyword">distinct</span> rating <span class="token keyword">from</span> film
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>ALL</td> <td></td> <td></td> <td></td> <td></td> <td>1000</td> <td>100.0</td> <td>Using temporary</td></tr></tbody></table> <blockquote><p>需要使用临时表，对数据进行去重</p></blockquote> <h2 id="_9-using-filesort">9.Using filesort</h2> <p><strong>using filesort</strong>：排序时无法使用到索引时，就会出现这个。常见于order by和group by语句中</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> 
<span class="token keyword">select</span> <span class="token punctuation">`</span>length<span class="token punctuation">`</span> <span class="token keyword">from</span> film <span class="token keyword">order</span> <span class="token keyword">by</span> <span class="token punctuation">`</span>length<span class="token punctuation">`</span>  
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>film</td> <td></td> <td>ALL</td> <td></td> <td></td> <td></td> <td></td> <td>1000</td> <td>100.0</td> <td>Using filesort</td></tr></tbody></table> <blockquote><p><code>length</code> 字段不是索引，需要借助临时表来进行排序</p></blockquote> <h2 id="_10-intersect-union">10.intersect union</h2> <ul><li>using intersect：表示使用and的各个索引的条件时，该信息表示是从处理结果获取交集</li> <li>using union：表示使用or连接各个使用索引的条件时，该信息表示从处理结果获取并集</li></ul> <p><strong>满足条件</strong></p> <ul><li>多个索引条件and</li> <li>多个索引添加or</li></ul> <p><strong>and</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> 
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> film 
<span class="token keyword">where</span>
film_id <span class="token operator">&lt;</span> <span class="token number">200</span>
<span class="token operator">and</span> title <span class="token operator">=</span> <span class="token string">'AFRICAN EGG'</span>
<span class="token operator">and</span> language_id <span class="token operator">=</span> <span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>Name</th> <th>Value</th></tr></thead> <tbody><tr><td>id</td> <td>1</td></tr> <tr><td>select_type</td> <td>SIMPLE</td></tr> <tr><td>table</td> <td>film</td></tr> <tr><td>partitions</td> <td></td></tr> <tr><td>type</td> <td>index_merge</td></tr> <tr><td>possible_keys</td> <td>PRIMARY,idx_title,idx_fk_language_id</td></tr> <tr><td>key</td> <td>idx_title,PRIMARY</td></tr> <tr><td>key_len</td> <td>516,2</td></tr> <tr><td>ref</td> <td></td></tr> <tr><td>rows</td> <td>1</td></tr> <tr><td>filtered</td> <td>100.0</td></tr> <tr><td>Extra</td> <td>Using intersect(idx_title,PRIMARY); Using where</td></tr></tbody></table> <p><strong>or</strong></p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> 
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> film 
<span class="token keyword">where</span>
film_id <span class="token operator">&lt;</span> <span class="token number">200</span>
<span class="token operator">or</span> title <span class="token operator">=</span> <span class="token string">'AFRICAN EGG'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><blockquote><p>太多的or，也不会<code>Using union</code></p></blockquote> <p><strong>执行计划结果</strong></p> <table><thead><tr><th>Name</th> <th>Value</th></tr></thead> <tbody><tr><td>id</td> <td>1</td></tr> <tr><td>select_type</td> <td>SIMPLE</td></tr> <tr><td>table</td> <td>film</td></tr> <tr><td>partitions</td> <td></td></tr> <tr><td>type</td> <td>index_merge</td></tr> <tr><td>possible_keys</td> <td>PRIMARY,idx_title</td></tr> <tr><td>key</td> <td>PRIMARY,idx_title</td></tr> <tr><td>key_len</td> <td>2,514</td></tr> <tr><td>ref</td> <td></td></tr> <tr><td>rows</td> <td>200</td></tr> <tr><td>filtered</td> <td>100.0</td></tr> <tr><td>Extra</td> <td>Using union(PRIMARY,idx_title); Using where</td></tr></tbody></table> <h2 id="_11-impossiable-where">11.impossiable where</h2> <p>impossiable where：where的值总fasle，不能获取任何记录</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> 
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> film 
<span class="token keyword">where</span> <span class="token number">1</span><span class="token operator">=</span><span class="token number">2</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td>Impossible WHERE</td></tr></tbody></table> <blockquote><p>where条件不成立就会出现</p></blockquote> <h2 id="_12-select-tables-optimized-away">12.Select tables optimized away</h2> <p>Select tables optimized away：在没有group by子句的情况下，基于索引优化的MAX/MIN操作，
或者基于MyISAM存储引擎优化的COUNT(*)操作，不必等到执行阶段再进行计算，在查询计划生成阶段既可以完成优化</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span> 
<span class="token keyword">select</span> <span class="token function">max</span><span class="token punctuation">(</span>film_id<span class="token punctuation">)</span> <span class="token keyword">from</span> film_actor
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td>Select tables optimized away</td></tr></tbody></table> <blockquote><p>因为<code>film_id</code>是索引字段，索引是有序的，可以直接获得最大的值</p></blockquote> <h2 id="_13-distinct">13.distinct</h2> <p>distinct：在select部分使用了distinc关键字。优化Distinct操作，在找到匹配的第一行记录后，立马停止查找同样的值</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> <span class="token keyword">distinct</span> fc<span class="token punctuation">.</span>category_id <span class="token keyword">from</span> film_category fc 
<span class="token keyword">left</span> <span class="token keyword">join</span> film f 
<span class="token keyword">on</span> f<span class="token punctuation">.</span>film_id <span class="token operator">=</span> fc<span class="token punctuation">.</span>film_id
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>fc</td> <td></td> <td>index</td> <td>PRIMARY,fk_film_category_category</td> <td>fk_film_category_category</td> <td>1</td> <td></td> <td>1000</td> <td>100.0</td> <td>Using index; Using temporary</td></tr> <tr><td>1</td> <td>SIMPLE</td> <td>f</td> <td></td> <td>eq_ref</td> <td>PRIMARY</td> <td>PRIMARY</td> <td>2</td> <td>sakila.fc.film_id</td> <td>1</td> <td>100.0</td> <td>Using index; Distinct</td></tr></tbody></table> <blockquote><p>一旦找到与之匹配的行，就不会在搜索</p></blockquote> <h2 id="_14-using-join-buffer">14.Using join buffer</h2> <p><strong>Block Nested-Loop Join算法</strong></p> <blockquote><p>将外层循环的行/结果集存入join buffer, 内层循环的每一行与整个buffer中的记录做比较，从而减少内层循环的次数。
优化器管理参数optimizer_switch中的block_nested_loop参数控制着BNL是否被用于优化器。
默认条件下是开启，若果设置为off，优化器在选择 join方式的时候会选择NLJ(Nested Loop Join)算法。</p></blockquote> <p><strong>Batched Key Access原理</strong></p> <blockquote><p>对于多表join语句，当MySQL使用索引访问第二个join表的时候，使用一个join buffer来收集第一个操作对象生成的相关列值。
BKA构建好key后，批量传给引擎层做索引查找。key是通过MRR接口提交给引擎的（mrr目的是较为顺序）MRR使得查询更有效率，
要使用BKA，必须调整系统参数optimizer_switch的值，batched_key_access设置为on，因为BKA使用了MRR，因此也要打开MRR</p></blockquote> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">explain</span>
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> category<span class="token punctuation">,</span> film_category 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>执行计划结果</strong></p> <table><thead><tr><th>id</th> <th>select_type</th> <th>table</th> <th>partitions</th> <th>type</th> <th>possible_keys</th> <th>key</th> <th>key_len</th> <th>ref</th> <th>rows</th> <th>filtered</th> <th>Extra</th></tr></thead> <tbody><tr><td>1</td> <td>SIMPLE</td> <td>category</td> <td></td> <td>ALL</td> <td></td> <td></td> <td></td> <td></td> <td>16</td> <td>100.0</td> <td></td></tr> <tr><td>1</td> <td>SIMPLE</td> <td>film_category</td> <td></td> <td>ALL</td> <td></td> <td></td> <td></td> <td></td> <td>1000</td> <td>100.0</td> <td>Using join buffer (hash join)</td></tr></tbody></table> <blockquote><p>两个表做笛卡尔积</p></blockquote> <h2 id="其他">其他</h2> <p>还有其他extra值，不能可能都列举完，有需要，大家可以查看官网或者一些其他文章补充下</p> <ul><li><a href="https://dev.mysql.com/doc/refman/8.0/en/explain-output.html#explain_extra" target="_blank" rel="noopener noreferrer">explain_extra<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/eagle89/article/details/80433681" target="_blank" rel="noopener noreferrer">MySQL中explain执行计划中额外信息字段(Extra)详解<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://segmentfault.com/a/1190000021458117" target="_blank" rel="noopener noreferrer">一张图彻底搞懂MySQL的explain<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div> <footer class="page-edit" style="display:none;"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">2021-1-15 5:37:43 PM</span></div></footer> <!----> <!----> <!----></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div><!----><!----><APlayer audio="" fixed="true" mini="true" theme="#f9bcdd" loop="loop" order="random" preload="auto" volume="0.1" mutex="true" lrc-type="0" list-folded="true" list-max-height="250" storage-name="vuepress-plugin-meting" id="aplayer-fixed"></APlayer></div></div>
    <script src="/manor-farm-mysql/assets/js/app.bbd54b43.js" defer></script><script src="/manor-farm-mysql/assets/js/3.33fa8ee0.js" defer></script><script src="/manor-farm-mysql/assets/js/1.e501e4e7.js" defer></script><script src="/manor-farm-mysql/assets/js/24.560a4164.js" defer></script><script src="/manor-farm-mysql/assets/js/8.73e907b5.js" defer></script>
  </body>
</html>
